<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/9/10
 * Time: 16:01
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class Examine extends Base {
    public function index(){
        if(request()->isAjax()){
            extract(input());
            $map =array();
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
//            if(isset($keyword)&&$keyword!="")
//            {
//                $map['a.user_username|a.user_phone'] = ['like',"%" . $keyword . "%"];
//            }
            if(isset($sex)&&$sex!="")
            {
                $map['user_status'] = $sex;
            }else{
                $map['user_status'] =array('not in',array(4,5,6));
            }
            $map['user_type'] =2;
            $count = Db::table('up_u_user')->alias('a')
                ->where($map)
                ->count();
            $list = Db::table('up_u_user')->alias('a')
                ->where($map)
                ->page($page, $limit)
                ->order('a.user_status asc, a.user_time desc')
                ->select();//计算总页面
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$list]);
        }
        return $this->fetch();
    }
    //详情
    public function detail(){
        $map['user_id'] = input('param.user_id');
        $list = Db::table('up_u_user')->alias('a')
            ->join('up_area ua','ua.district_id = a.user_sheng','left')
            ->join('up_area ua1','ua1.district_id = a.user_shi','left')
            ->join('up_area ua2','ua2.district_id = a.user_qu','left')
            ->join('up_grade ug','ug.grade_id = a.user_grade','left')
            ->join('up_subject us','us.subject_id = a.user_subject','left')
            ->join('up_teach_style uts','uts.style_id =a.user_tcahe_style','left')
            ->where($map)
            ->field('a.*,ua.district,ua1.district as district1,
                ua2.district as district2,ug.grade_name,us.subject_name,uts.style_name')
            ->find();//计算总页面
        $list['address'] = $list['district'].$list['district1'].$list['district2'];
        $list['star'] = $this->teacherStar($list['user_id']);
        if($list['user_gender']==1){
            $list['user_gender_name'] = '男';
        }else{
            $list['user_gender_name'] = '女';
        }
        if($list['user_honor_img']){
            $list['user_honor_img'] = explode(',', trim($list['user_honor_img'], ','));
        }else{
            $list['user_honor_img'] = [];
        }
        $this->assign('list',$list);
        return $this->fetch();
    }
    //通过
    public function examine(){
        $ids = input('id');
        $res = Db::table('up_u_user')->where('user_id', $ids)->setField('user_status', 2);
        if($res){
            return json(['code' => 200, 'msg' => "操作成功"]);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    //驳回
    public function reject(){
        if(Request::instance()->isPost()){
            $ids = input('param.id');
            $data['user_status'] = 3;
            $data['reject'] = input('param.reject');
            if(mb_strlen($data['reject'],"utf-8")>30){
                return json(['code' => 100, 'msg' => '不能超过30额字符']);
            }
            $res = Db::table('up_u_user')->where('user_id', $ids)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $id = input('param.user_id');
        $this->assign('id',$id);
        return $this->fetch();
    }
}